package com.example.exp3.service;

import learn.ScheduledTasks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class ScheduleTask {
    private static final Logger log = LoggerFactory.getLogger(ScheduledTasks.class);
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    static public  COVID19CSV covid19csv = new COVID19CSV();

    @Scheduled(fixedRate = 600000)
    public void updateData() {
        try {
            covid19csv.updateCsv();
        } catch (IOException e) {
            e.printStackTrace();
        }
        log.info("Updated in {}", dateFormat.format(new Date()));
    }
}
